package com.zyl.xiaoshou.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zyl.xiaoshou.pojo.YuDingVo;
import com.zyl.xiaoshou.service.YuDingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/yuding")
public class YuDingController {
    @Autowired
    private YuDingService yuDingService;

    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list(Integer page, Integer limit, String fname) {


        Page<Object> objects = PageHelper.startPage(page, limit);
        List<YuDingVo> list = yuDingService.list(fname);
        long total = objects.getTotal();
        System.out.println(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", list);
        map.put("count", total);
        return map;
    }

    @RequestMapping("/add")
    public String add() {
        return "list";
    }

    @RequestMapping("/delete")
    public void delete(int fid, HttpServletResponse response) throws IOException {
        int update = yuDingService.update(fid);
        if (update > 0) {
            response.getWriter().print("<script>alert('删除成功');location.href='/yuding/add'</script>");
        }
    }


    public void xuzu(int fid) {
//        String zuqu=


    }

}
